from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from hyrobot.common import GSTORE


def open_browser():

    print('打开浏览器')
    wd = webdriver.Firefox()
    wd.implicitly_wait(5)

    # 使用黑羽robot 全局存储对象 GSTORE
    GSTORE['global_webdriver'] = wd
    return wd

def mgr_login(wd):
    wd.get("http://172.17.66.19:8080/")

    wd.find_element(By.NAME, "username").send_keys("sunxidong")
    wd.find_element(By.NAME, "password").send_keys("123456")
    wd.find_element(By.CSS_SELECTOR, ".el-button").click()

# 获取 全局使用的 webdriver 对象
def get_global_webdriver():
    return GSTORE['global_webdriver']

def logout(driver):
    time.sleep(2)
    driver.find_element(By.CSS_SELECTOR,
    ".avatar-wrapper > span:nth-child(1)").click()
    time.sleep(3)
    driver.find_element(By.CSS_SELECTOR,
    "li.el-dropdown-menu__item:nth-child(2) > span:nth-child(1)").click()



# from lib.webui import  *

# class c0101:
#     name = '管理员首页 - UI-0101' # 测试用例名字
#
# 初始化方法
#     def setup(self):
# #       STEP(1, '登陆网站')
#         wd = open_browser()
#         mgr_login(wd)
#
#     #清除方法
#     def teardown(self):
#         wd = get_global_webdriver()
#         wd.quit()
#
#     # 测试用例步骤
#     def teststeps(self):
#         # 获取webdriver对象 对应 已经登录好的浏览器
#         wd = get_global_webdriver()